package ace.tool.generate.code.impl.resolver.scheme.resolver.core;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.CoreConstantClassInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ClassFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.CommonInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import ace.tool.generate.code.impl.resolver.scheme.resolver.ClassFileInfoResolver;
import ace.tool.generate.code.impl.service.model.input.GenerateInput;
import lombok.Builder;
import lombok.RequiredArgsConstructor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class CoreConstantClassInfoResolver {
  private final GenerateInput input;
  private final ProjectInfo coreProjectInfo;
  private final CommonInfo commonInfo;

  public CoreConstantClassInfo resolve() {

    ClassFileInfo classFileInfo =
        ClassFileInfoResolver.builder()
            .className(commonInfo.getProjectClassName())
            .classNameSuffix(input.getCoreConstantClassNameSuffix())
            .classPackagePrefix(input.getCoreConstantClassPackagePrefix())
            .rootPackageFullName(commonInfo.getRootPackageFullName())
            .sourceCodeRootDir(coreProjectInfo.getSourceCodeRootDir())
            .build()
            .resolve();

    return CoreConstantClassInfo.builder().info(classFileInfo).dsName(this.getDsName()).build();
  }

  private String getDsName() {
    return input.getProjectName().replaceAll("-", "_");
  }
}
